
package jogoprojetopi;

import java.awt.event.*;
import s3t.gameControl.system.GameSystem;
import s3t.gameElements.Element;


public class Keyboard extends KeyAdapter implements KeyListener {

    public static boolean keyUp = false;
    public static boolean keyDown = false;
    public static boolean keyLeft = false;
    public static boolean keyRight = false;
    public static boolean SPACEBAR = false;
    public static boolean ENTER = false;
    public static int key;

    static Object getKey() {
        String keyPressed = "";

        if( ENTER )
        {
            keyPressed = "ENTER";
        }
        
        return keyPressed;
    }
    
    /********************
     * Eventos de teclado
     *********************/
    @Override
    public void keyTyped(KeyEvent keyEvent) {
    }

    @Override
    public void keyPressed(KeyEvent keyEvent) {
        int k = keyEvent.getKeyCode();
        key = keyEvent.getKeyCode();

        Element player = GameSystem.getInstance().getElementCollection().getElementByName("Personagem");

        
        if( key == KeyEvent.VK_ENTER )
        {
            ENTER = true;
        }

        if (k == KeyEvent.VK_LEFT)
        {
            keyLeft = true;
        }
        if (k == KeyEvent.VK_RIGHT)
        {
            keyRight = true;
        }
        if (k == KeyEvent.VK_UP)
        {
            keyUp = true;
        }
        if (k == KeyEvent.VK_DOWN)
        {
            keyDown = true;
        }
        if (k == KeyEvent.VK_SPACE)
        {
            SPACEBAR = true;
        }
        if (k == KeyEvent.VK_SHIFT)
        {
            GameSystem.getInstance().getAIEngine().sendMessage(player, "desarmar", 0);
        }
    }

    @Override
    public void keyReleased(KeyEvent keyEvent) {
        int k = keyEvent.getKeyCode();

        Element player = GameSystem.getInstance().getElementCollection().getElementByName("Personagem");
        Element bomba = GameSystem.getInstance().getElementCollection().getElementByName("Bomba");

        if (k == KeyEvent.VK_LEFT)
        {
            keyLeft = false;
        }
        if (k == KeyEvent.VK_RIGHT)
        {
            keyRight = false;
        }
        if (k == KeyEvent.VK_UP)
        {
            keyUp = false;
        }
        if (k == KeyEvent.VK_DOWN)
        {
            keyDown = false;
        }
        if (k == KeyEvent.VK_SPACE)
        {
            GameSystem.getInstance().getAIEngine().sendMessage(player, "voltarAtaque", 0);
            SPACEBAR = false;
        }
        if(k == KeyEvent.VK_SHIFT)
        {
            GameSystem.getInstance().getAIEngine().sendMessage(player, "pararDesarmar", 0);
            GameSystem.getInstance().getAIEngine().sendMessage(bomba, "pararDesarmar", 0);
        }
    }
}
